#include "main.h"

void Init_Muxter(void)
{
//1：初始化 MUXER通道

    MUXER_CHN_ATTR_S stMuxerAttr;
	memset(&stMuxerAttr, 0, sizeof(stMuxerAttr));
	stMuxerAttr.u32MuxerId = 0;
	stMuxerAttr.enMode = MUXER_MODE_AUTOSPLIT;
	stMuxerAttr.enType = MUXER_TYPE_MP4;
	stMuxerAttr.stSplitAttr.enSplitType = MUXER_SPLIT_TYPE_TIME;
	stMuxerAttr.stSplitAttr.u32TimeLenSec = 30;
	stMuxerAttr.stSplitAttr.enSplitNameType = MUXER_SPLIT_NAME_TYPE_AUTO;
    stMuxerAttr.stSplitAttr.stNameAutoAttr.pcPrefix = "muxer_test";
    stMuxerAttr.stSplitAttr.stNameAutoAttr.pcBaseDir = "/sdcard";
	stMuxerAttr.stSplitAttr.stNameAutoAttr.u16StartIdx = 1;
    // Split File name with timestamp.
    // stMuxerAttr.stSplitAttr.stNameAutoAttr.bTimeStampEnable = RK_TRUE;

	stMuxerAttr.stVideoStreamParam.enCodecType = RK_CODEC_TYPE_H264;
	stMuxerAttr.stVideoStreamParam.enImageType = IMAGE_TYPE_NV12;
	stMuxerAttr.stVideoStreamParam.u16Fps = 30;
	stMuxerAttr.stVideoStreamParam.u16Level = 41;    // for h264
	stMuxerAttr.stVideoStreamParam.u16Profile = 100; // for h264
	stMuxerAttr.stVideoStreamParam.u32BitRate = 1920*1080;
	stMuxerAttr.stVideoStreamParam.u32Width = 1920;
	stMuxerAttr.stVideoStreamParam.u32Height = 1080;

	stMuxerAttr.stAudioStreamParam.enCodecType = RK_CODEC_TYPE_MP2;
	stMuxerAttr.stAudioStreamParam.enSampFmt = RK_SAMPLE_FMT_S16;
	stMuxerAttr.stAudioStreamParam.u32Channels = 2;
	stMuxerAttr.stAudioStreamParam.u32NbSamples = 1152;
	stMuxerAttr.stAudioStreamParam.u32SampleRate = 48000;
	int ret = RK_MPI_MUXER_EnableChn(0, &stMuxerAttr);
	if (ret) {
		printf("Create MUXER[0] failed! ret=%d\n", ret);
		return ;
	}
    RK_MPI_MUXER_StreamStart(0);
//2：绑定 AENC->MUXER   VENC->MUXER
    MPP_CHN_S src;
    MUXER_CHN_S stMuxerChn;
    src.enModId=RK_ID_VENC;
    src.s32ChnId=0;
    src.s32DevId=0;

    stMuxerChn.enModId = RK_ID_MUXER;
	stMuxerChn.enChnType = MUXER_CHN_TYPE_VIDEO;
	stMuxerChn.s32ChnId = 0;
    RK_MPI_MUXER_Bind(&src, &stMuxerChn);
  
    src.enModId=RK_ID_AENC;
    src.s32ChnId=0;
    src.s32DevId=0;

    stMuxerChn.enModId = RK_ID_MUXER;
	stMuxerChn.enChnType = MUXER_CHN_TYPE_AUDIO;
	stMuxerChn.s32ChnId = 0;
    RK_MPI_MUXER_Bind(&src, &stMuxerChn);
}

